<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Parts_Endorsement extends Page
{
       public $hiddenParts = null;
       public $hiddenWO = null;
       public $hiddenVeh = null;
       public $Image1 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $memoNotes = null;
       public $lblNotes = null;
       public $JTDate = null;
       public $Label1 = null;
       public $JTSiteTheme1 = null;
       function Parts_EndorsementJSUnload($sender, $params)
       {

       ?>
       //Add your javascript code here
       var wo=document.getElementById("hiddenWO").value;
       //alert("rarararara");
       var veh=document.getElementById("hiddenVeh").value;
       var part=document.getElementById("hiddenParts").value;
       //window.open("veh_parts_edit.php?veh="+veh+"&WO="+wo+"&parts="+part,"Window2","menubar=no,width=664,height=336,left=350,top=250,toolbar=no");
       window.location.href = "veh_parts_edit.php?veh="+veh+"&WO="+wo+"&parts="+part;
       //window.close();
       <?php

       }

       function btnCancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }

       function btnSubmitClick($sender, $params)
       {
       $filename = "temp/parts_update.txt";
       $handle = fopen($filename, "r");
       $contents = fread($handle, filesize($filename));
       mysql_query($contents) or die("PARTS UPDATE ".mysql_error());
       fclose($handle);

       if($_GET['flag1']=='1')
       {
       $filename = "temp/parts_inv_update_1.txt";
       $handle = fopen($filename, "r");
       $contents1 = fread($handle, filesize($filename));
       mysql_query($contents1) or die("PARTS INV 1 UPDATE ".mysql_error());
       fclose($handle);
       }

       if($_GET['flag2']=='1')
       {
       $filename = "temp/parts_inv_update_2.txt";
       $handle = fopen($filename, "r");
       $contents2 = fread($handle, filesize($filename));
       mysql_query($contents2) or die("PARTS INV 2 UPDATE ".mysql_error());
       fclose($handle);
       }

       mysql_query("INSERT INTO endorsement_parts_tbl(company_id,
       veh_id,
       wo_id,
       parts_id,
       date,
       reason,
       endorsed_by)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$this->hiddenVeh->getValue()."',
       '".$this->hiddenWO->getValue()."',
       '".$this->hiddenParts->getValue()."',
       '".$this->JTDate->Text."',
       '".$this->memoNotes->Text."',
       '".$_SESSION['username']."')") or die("INSERT ENDO_PARTS - ".mysql_error());

        echo '<script language=javascript>
        window.opener.parent.setWODetails();
        window.opener.location.reload();
        alert("Successfully Updated Record!");
        window.close();
        </script>';
       //redirect('veh_laborline_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue());
       /*echo '<script language=javascript>
       var wo = document.getElementById("hiddenWO").value;
       alert("rarararara");
       var veh=document.getElementById("hiddenVeh").value;
       var labor=document.getElementById("hiddenLabor").value;
       window.open("veh_laborline_edit.php?veh="+veh+"&WO="+wo+"&laborline="+labor,"Window1","menubar=no,width=664,height=336,left=350,top=250,toolbar=no");
       window.close();
       </script>';*/
       }

       function Parts_EndorsementCreate($sender, $params)
       {
       $veh = $_GET['veh'];
       $WO = $_GET['WO'];
       $parts = $_GET['parts'];
       $this->hiddenVeh->setValue($veh);
       $this->hiddenWO->setValue($WO);
       $this->hiddenParts->setValue($parts);

       $this->JTDate->setText(date('Y-m-d'));
       $this->memoNotes->Lines=array();

       }

}

global $application;

global $Parts_Endorsement;

//Creates the form
$Parts_Endorsement=new Parts_Endorsement($application);

//Read from resource file
$Parts_Endorsement->loadResource(__FILE__);

//Shows the form
$Parts_Endorsement->show();

?>